package com.lyfei.ydc.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lyfei.ydc.domain.entity.Spu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.lyfei.ydc.service.SearchService;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("")
    public IPage<Spu> search(@RequestParam String q,
                             @RequestParam(defaultValue = "0") Integer start,
                             @RequestParam(defaultValue = "10") Integer count) {

        Integer page = start / count + 1;
        return searchService.search(q, page, count);
    }
}
